<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<style>
			.box {
				display: flex;
				width: 200px;
				height: 200px;
				background-color: orange;
			}
			.box span {
				width: 100px;
				height: 100px;
				background-color: #f00;
			}
		</style>
	</head>
	<body>
		<a href="http://www.baidu.com">百度一下</a>
		<div class="box">
			<span><button>按钮</button></span>
		</div>

		<script>
			var aEl = document.querySelector('a')
			aEl.addEventListener('click', function (e) {
				alert('a被点击了')
				e.preventDefault()
			})

			var btnEl = document.querySelector('button')
			var spanEl = document.querySelector('span')
			var divEl = document.querySelector('div')

			divEl.addEventListener(
				'click',
				function (e) {
					console.log('div的事件捕获')
					// e.stopPropagation()
				},
				true
			)

			spanEl.addEventListener(
				'click',
				function (e) {
					console.log('span的事件捕获')
				},
				true
			)

			btnEl.addEventListener(
				'click',
				function (e) {
					console.log('btn的事件捕获')
				},
				true
			)

			divEl.addEventListener('click', function (e) {
				console.log('div的事件冒泡')
			})

			spanEl.addEventListener('click', function (e) {
				console.log('span的事件冒泡')
				e.stopPropagation()
			})

			btnEl.addEventListener('click', function (e) {
				console.log('btn的事件冒泡')
			})
		</script>
	</body>
</html>
